<template>
	<view class="u-wrap" :class="['qn-page-' + theme]">
		<view class="u-menu-wrap">
			<scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view" :scroll-top="scrollTop">
				<view class="u-tab-ul" v-for="(item, index) in cate_list" :key="index">
					<view class="u-tab-item" :class="[now_cate.id == item.id ? 'u-tab-item-active' : '']" :data-current="item.title" @tap.stop="swichMenu(item)">
						<text class="u-line-1">{{ item.title }}</text>
					</view>
				</view>
			</scroll-view>
			<view class="right-box">
				<view class="u-search-box" @click="goPage('/pages/search/index')">
					<view class="u-search-inner">
						<u-icon name="search" :color="primaryColor" :size="28"></u-icon>
						<text class="u-search-text">请输入关键词</text>
					</view>
				</view>
				<scroll-view scroll-y class="right-box-scroll">
					<view class="page-view">
						<view class="cate-poster" v-if="now_cate.adImage"><u-image width="100%" height="194rpx" :src="now_cate.adImage"></u-image></view>
						<view class="item-title">
							<text>{{ now_cate.title }}</text>
						</view>
						<view class="goods-ul">
							<view class="cate-two" @click="goPage('/pages/cate/cateGoods?id=' + now_cate.id + '&name=' + now_cate.title)">
								<image class="cate-img" :src="now_cate.images" mode="aspectFit"></image>
								<view class="cate-name">{{ now_cate.title }}</view>
							</view>
							<block v-for="(item, index) in cata_child" :key="index">
								<view class="cate-two" @click="goPage('/pages/cate/cateGoods?id=' + item.id + '&name=' + item.title)">
									<image class="cate-img" :src="item.images" mode="aspectFit"></image>
									<view class="cate-name">{{ item.title }}</view>
								</view>
							</block>
							<!-- <Aempty text="没有子分类～～" left="80rpx" src="../../static/empty/data.png" v-if="!cata_child.length"></Aempty> -->
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			t_current: 1, // 底部Tabbar，不要动
			cata_child: [], // 分类二级列表
			cate_list: [], // 分类列表
			scrollTop: 0, //tab标题的滚动条位置
			menuHeight: 0, // 左边菜单的高度
			menuItemHeight: 0, // 左边菜单item的高度
			now_cate: {}
		};
	},
	created() {
		this.getAllCate();
	},
	methods: {
		getAllCate() {
			this.$u.api.getAllCate().then(({ data }) => {
				this.cate_list = data;
				if (data.length) {
					this.now_cate = data[0];
					this.cata_child = data[0].children || [];
				}
			});
		},

		// 点击左边的栏目切换
		async swichMenu(row) {
			if (row.id == this.categoryId) return;
			this.now_cate = row;
			this.cata_child = row.children || [];
		}
	}
};
</script>

<style lang="scss" scoped>
.u-wrap {
	// height: calc(100vh);
	/* #ifdef H5 */
	// height: calc(100vh - var(--window-top));
	/* #endif */
	display: flex;
	flex-direction: column;
}

.u-search-box {
	padding: 18rpx 30rpx;
	background-color: #ffffff;
	.u-search-inner {
		background-color: #f9f9f9;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		padding: 10rpx 20rpx;

		.u-search-text {
			font-size: 24rpx;
			color: $u-tips-color;
			margin-left: 20rpx;
		}
	}
}

.u-menu-wrap {
	flex: 1;
	display: flex;
	overflow: hidden;
}

.u-tab-view {
	width: 200rpx;
	height: calc(100vh - 100rpx);
	background-color: #f9f9f9;
	z-index: 1;
}

.u-tab-item {
	height: 100rpx;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 28rpx;
	color: #333333;
	font-weight: 400;
	line-height: 1;
}

.u-tab-item-active {
	position: relative;
	// color: #000;
	// font-size: 30rpx;
	// font-weight: 600;
	background: #ffffff;
}

.u-tab-item-active::before {
	content: '';
	position: absolute;
	border-left: 6rpx solid #f63434;
	height: 30rpx;
	left: 0;
	top: 50%;
	transform: translateY(-50%);
}

.right-box {
	width: 650rpx;
	background-color: #ffffff;
	.right-box-scroll {
		height: calc(100vh - 190rpx);
	}
}

.page-view {
	padding: 0 22upx 22rpx;
	.cate-poster {
		border-radius: 12upx;
		overflow: hidden;
	}
}

.item-title {
	font-size: 28rpx;
	color: $u-main-color;
	line-height: 130upx;
	text-align: center;
}
.goods-ul {
	display: flex;
	flex-wrap: wrap;
	background-color: #ffffff;
	border-radius: 12upx;
	overflow: hidden;
	margin-bottom: 20px;

	.cate-two {
		width: 33.3333%;
		text-align: center;
		.cate-img {
			width: 150rpx;
			height: 150rpx;
			display: inline-block;
			border-radius: 8rpx;
		}
		.cate-name {
			font-size: 26upx;
			padding-top: 10rpx;
		}
	}
}
</style>
